package Collections;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by Xiang on 2014/8/17.
 * This is a test
 */
public class LinkedListTest {
    public static void main(String[] args) {
        List<String> a = new ArrayList<String>();
        a.add("Amy");
        a.add("Carl");
        a.add("Erica");

        List<String> b = new ArrayList<String>();
        b.add("Bob");
        b.add("Doug");
        b.add("France");
        b.add("Gloria");

        ListIterator<String> aIter = a.listIterator();
        Iterator<String> bIter = b.iterator();

//        将b中的元素依次插入到a中的元素之后
        while (bIter.hasNext()) {
            if (aIter.hasNext()) aIter.next();
            aIter.add(bIter.next());
        }

        System.out.println(a);

        bIter = b.iterator();

//        隔一个删除一个b中的元素
        while (bIter.hasNext()) {
            bIter.next();
            if (bIter.hasNext()) {
                bIter.next();
                bIter.remove();
            }
        }

        System.out.println(b);

//        删除a中属于b中的元素
        a.removeAll(b);
        System.out.println(a);

    }
}
